package com.neuedu.hisadmin.controller;

import com.neuedu.hisadmin.dto.LoginDTO;
import com.neuedu.hisadmin.dto.Result;
import com.neuedu.hisadmin.entity.User;
import com.neuedu.hisadmin.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jaun
 * @since 2025-07-05
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;
    @PostMapping("/login")
    public Result<User> login(@RequestBody LoginDTO loginDTO) {
        User user = userService.login(loginDTO.getUsername(), loginDTO.getPassword());

        if (user == null) {
            return Result.error(401, "用户名或密码错误");
        }

        // 实际项目中应返回 token 而不是完整用户信息
        return Result.success(user);
    }
}


